package com.tencreat.mall.controller.app;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.domain.mall.MallCollect;
import com.tencreat.domain.mall.MallConsult;
import com.tencreat.domain.mall.MallPraise;
import com.tencreat.domain.mall.dto.CollectAddDTO;
import com.tencreat.domain.mall.dto.PraiseAddDTO;
import com.tencreat.domain.mall.vo.ResMallCollectVO;
import com.tencreat.service.mall.IMallCollectService;
import com.tencreat.service.mall.IMallConsultService;
import com.tencreat.service.mall.IMallPraiseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 *  关注Controller
 *
 * @author wangkai
 * @date 2021-11-15
 */
@Api(tags = "98-点赞api")
@RestController
@RequestMapping("/api/praise")
public class MallPraiseController extends BaseController {
    @Autowired
    private IMallPraiseService mallPraiseService;

    @ApiOperation("点赞/取消赞")
    @PostMapping("/add")
    public HttpResult add(@RequestBody @Validated PraiseAddDTO dto) {
        mallPraiseService.save(dto);

        return HttpResult.ok();
    }

    @ApiOperation("是否收藏")
    @GetMapping("/isPraise")
    public HttpResult<Boolean> isPraise(PraiseAddDTO dto) {
        Long uuid = getLoginCheck().getAccountLogin().getUuid();
        int count = mallPraiseService.lambdaQuery()
                .eq(MallPraise::getUserId, uuid)
                .eq(MallPraise::getType, dto.getType())
                .eq(MallPraise::getValueId, dto.getValueId())
                .count();
        if (count > 0) {
            return HttpResult.ok(Boolean.TRUE);
        }
        return HttpResult.ok(Boolean.FALSE);
    }
}
